<template>
	<view>
		<uni-list>
			<uni-list-chat :avatar-circle="true" v-for="(item,index) in news" :key="index" :avatar="item.author_avatar"
				:title="item.author_name" :note="item.title" :to="`info?id=`+item.post_id" :time="item.created_at"
				:clickable="true">
			</uni-list-chat>
		</uni-list>
	</view>
</template>

<script>
	var dateUtils = require('../../../common/util.js').dateUtils;
	import uniListChat from '@/components/uni-list-chat/uni-list-chat.vue'
	import uniList from '@/components/uni-list/uni-list.vue'
	export default {
		data() {
			return {
				news: []
			}
		},
		onPullDownRefresh() {
			this.refreshList()
		},
		onLoad() {
			this.refreshList()
		},
		onShow() {
			this.refreshList()
		},
		methods: {
			info(e) {
				console.log(e)
				var messageId = e.currentTarget.dataset.messageId
			},
			refreshList() {
				uni.request({
					url: 'https://unidemo.dcloud.net.cn/api/news',
					method: 'GET',
					data: {},
					success: res => {
						console.log(res)
						this.news = res.data.map(item => {
							var created_at = dateUtils.parse(item.created_at)
							item.created_at = dateUtils.humanize(created_at.getTime() / 100)
							return item
						})
					},
					fail: () => {},
					complete: () => {
						uni.stopPullDownRefresh()
					}
				});
			},
			openInfo(e) {
				console.log(e);

			}
		}
	}
</script>

<style>

</style>
